<?php
// +----------------------------
// | Created by PhpStorm
// +----------------------------
// | Author: YnnSon
// +----------------------------
namespace app\api\model;

use app\lib\enum\PageEnum;
use app\lib\enum\SysmsgEnum;

/**
 * 系统消息和关于我们
 * Class SysmsgAbout
 * @package app\api\model
 */
class SysmsgAbout extends BaseModel
{
    // 类型自动转换
    protected $type = [
        'create_time' => 'timestamp:Y-m-d',
    ];

    /**
     * @Desc 获取系统消息和关于我们
     *
     * @param int $type 类型
     * @param int $page 页码
     *
     * @return array|bool|false|\PDOStatement|string|\think\Collection|\think\Model|null
     */
    public static function getSysmsgList($type, $page = 1)
    {
        // 分页数量
        $listRows = PageEnum::SYSMSG;
        $list = [];
        if (SysmsgEnum::SYSMSG == $type) {
            $field = 'id, title, content, create_time';
            $list = (new self)->field($field)->where('is_about', '=', SysmsgEnum::SYSMSG)->where('is_delete', '=', 0)->page($page, $listRows)->order('update_time desc')->select();
        }
        if (SysmsgEnum::ABOUTUS == $type) {
            $field = 'title, content, mobile, address';
            $list = (new self)->field($field)->where('is_about', '=', SysmsgEnum::ABOUTUS)->where('is_delete', '=', 0)->page($page, $listRows)->find();
        }
        return $list;
    }

    /**
     * @Desc 获取系统消息详情
     *
     * @param $id
     *
     * @return array|bool|false|\PDOStatement|string|\think\Model
     */
    public static function getSysmsgDetail($id)
    {
        $field = 'title, content, create_time';
        return (new self)->field($field)->where('id', '=', $id)->where('is_delete', '=', 0)->find();
    }

    /**
     * @Desc 获取更新信息
     * @return array|bool|false|\PDOStatement|string|\think\Model|null
     */
    public static function getUpdate()
    {
        $field = 'title, content, is_delete, create_time start_time, update_time end_time';
        return (new self)->field($field)->where('is_about', '=', SysmsgEnum::UPDATE)->find();
    }
}